<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>登录</title>
		<link href="css/mui.min.css" rel="stylesheet" />
		<script src="js/mui.js"></script>
		<style>
			html, body{
				height:100%;
				width:100%;
				padding: 0;
				margin: 0;
			}
			
			body{
				background: url(image/u=675629265,2686821793&fm=26&gp=0.jpg);
				background-size:cover;
				background-repeat: no-repeat;
			}
			
			.con{
				height: 50%; 
			}
			
			.con_top{
				text-align: center;
			}
			
			img{
				width: 50%; 
				margin: 20%;
			}
			
			input[type=text]{
				margin: 10% ;
			}
			
			input[type=password]{
				margin: 0 0 0 10%; 
			}
			
			input[type=text], input[type=password]{
				width: 80%; 
				height:11%; 
				border-radius: 10px;
				padding-left: 5%;
				background: rgba(255,255,255,0.3);
				border: 0px;
				transition: 0.3s all ease;
			}
			
			input[type=text]:focus, input[type=password]:focus{
				box-shadow: rgb(105, 187, 209) 0 0 28px;
				border: 0px;
			}
			
			button{
				width: 80%; 
				margin: 10% ; 
				height:15%; 
				border-radius: 10px; 
				background: #1296db;
			}
			
			p{
				text-align: center; 
				color:#554292
			}
			
		</style>

	</head>
	<body>
		<div class="con con_top">
			<img src="image/Box2.png">
		</div>
		<div class="con">
			<input type="text" id='account' placeholder="请输入用户账号" onkeyup="value=value.replace(/[^\d]/g,'')"/>
			<input type="password" id='password' placeholder="请输入密码" onkeyup="value=value.replace(/[^\d]/g,'')"/>
			<button id='login'>登录</button>
			<p><a href="reg.html">没有账号？点我注册</a></p>
		</div>
	</body>

	<script>
		var uID;
		
		//验证自动登录
		mui.plusReady(function() {
			uID = plus.storage.getItem("uID");
			if (uID && uID > 0) {
				mui.openWindow({
					url: "index.html",
				});
			}
		});

		document.getElementById("login").addEventListener('tap', function(e) {
			var account = document.getElementById('account').value;
			var password = document.getElementById('password').value;
			if (account.length === 0 || password.length === 0) {
				mui.toast("请输入账号与密码");
				return;
			}
			//ajax传值 
			mui.ajax({
				url: 'http://120.27.247.180:8080/School/users/Login',
				type: "post",
				data: {
					"uID": account,
					'password': password
				},
				dataType: "jsonp",
				contentType: "application/x-www-form-urlencoded; charset=utf-8",
				jsonp: "jsoncallback",
				success: function(data) {
					data = JSON.parse(data);
					if(data['suc']){ 
						mui.toast(data['msg']);
						plus.storage.setItem('uID',account);
						mui.openWindow({
							url: "index.html",
						});
					}else{
						mui.toast(data['msg']);
					}
				},
				error: function() {
					mui.toast("服务器异常，请稍后再试");
				}
			});
		});
	</script>
</html>
